import java.io.*;


public class function implements disk{
    //下载文件
    @Override
    public void read() {

    }
//上传文件
@Override
public void write(String location) {

    try {
        //获取文件名（去除前置文件目录），用于创建文件
        char separator = File.separatorChar;
        int lastIndex = location.lastIndexOf(separator);
        String fileName=null;
        if (lastIndex != -1) {
            fileName = location.substring(lastIndex + 1);
            System.out.println(fileName);
        } else {
            System.out.println("error：没有找到任何文件名");
        }
        //将存储目录整合为一个字符串
        String path = "disk/"+fileName;
        //创建文件，如果为true 将文件复制到目录里，如果为false表示文件已经存在或名字重复
        File f = new File(path);
        if (f.createNewFile()){
            System.out.println("文件创建成功");
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(location));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(path));
            byte[] b = new byte[1024];
            int len;
            while ((len = bis.read(b)) != -1) {
                bos.write(b, 0, len);
            }
            bos.close();
            bis.close();
            System.out.println("文件上传成功");
        }else{
            System.out.println("文件创建失败--已存在");
        }


    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.out.println("文件上传结束");
    }

    }
//删除文件
    @Override
    public void delete() {

    }
//查询已经存在的文件
    @Override
    public void select() {
        String path = "disk";
        File file = new File(path);
        File[] files = file.listFiles();
        for (File f : files) {
            System.out.println(f.getName());
        }

    }
}
